﻿using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zhy.PrismRegion.Composite.ViewModels
{
    public class ViewAViewModel: 
        INavigationAware // 接收导航参传递接口
    {
        /// <summary>
        /// 保存按钮
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }
        /// <summary>
        /// 关闭按钮
        /// </summary>
        public DelegateCommand CloseCommand { get; set; }
        /// <summary>
        /// 复合命令用于执行全部保存等操作使用
        /// </summary>
        CompositeCommand _composite;
        /// <summary>
        /// 全部保存的复合命令
        /// </summary>
        CompositeCommand _allSaveComposite;

        public ViewAViewModel(CompositeCommand composite,AllSaveCompositeCommand allSaveComposite)
        {
            SaveCommand = new DelegateCommand(() => // 保存按钮
            {


            });
            CloseCommand = new DelegateCommand(() => // 关闭按钮
            {


            });
            _allSaveComposite = allSaveComposite;
            _composite = composite;
            _allSaveComposite.RegisterCommand(SaveCommand); // 复合命令注册保存按钮
            composite.RegisterCommand(CloseCommand); // 复合命令注册保存按钮
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        /// <summary>
        /// 从当前View导航离开的时候触发
        /// </summary>
        /// <param name="navigationContext"></param>
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            _allSaveComposite.UnregisterCommand(SaveCommand);
            _composite.UnregisterCommand(CloseCommand);  // 当页面关闭时移除复合操作指令
        }
    }
}
